package com.ziiwee.reduce.describe.creators.controllers;

import com.ziiwee.reduce.describe.HandlerDescribe;
import com.ziiwee.reduce.describe.utils.DescribeUtil;
import com.ziiwee.reduce.rest.auto.ResourceInfo;
import org.springframework.core.ResolvableType;

import java.lang.reflect.AnnotatedElement;
import java.util.List;

/**
 * @author ziiwee
 * @since 2020/8/21
 */
public class ResourceInfoControllerDescribeCreator extends AbstractControllerDescribeCreator {

    private final ResourceInfo resourceInfo;

    public ResourceInfoControllerDescribeCreator(ResourceInfo resourceInfo) {
        this.resourceInfo = resourceInfo;
    }

    @Override
    public AnnotatedElement getElement() {
        return resourceInfo.getType();
    }

    @Override
    public ResolvableType getDefaultType() {
        return ResolvableType.forClass(resourceInfo.getType());
    }

    @Override
    public List<HandlerDescribe> getHandlers() {
        return DescribeUtil.createHandlers(null,resourceInfo.getService(), getSubjectType(), ResolvableType.forClass(resourceInfo.getIdType()), resourceInfo.getCommonService());
    }

    @Override
    public ResolvableType getSubjectType() {
        return ResolvableType.forClass(resourceInfo.getType());
    }
}
